import { request } from '@/utils/request';

const BASE_API = '/admin/file';

export const APIS = {
  insertFile: `${BASE_API}/insertFile`,
  downFile: `${BASE_API}/downFile`,
  uploadFile: `${BASE_API}/upload`,
};

interface GetOriginFileInfoParams {
  fileName: string;
  areaNum: number;
  md5: string;
}

interface GetOriginFileInfoResult {
  has: boolean;
  id: string;
  url: string;
}

export function getOriginFileInfo(params: GetOriginFileInfoParams): Promise<GetOriginFileInfoResult> {
  return request.get({
    url: APIS.insertFile,
    params,
  });
}

interface UploadFileParams {
  file: File;
  area: number;
  md5: string;
  id: string;
}

export function uploadFileApi(requestData: UploadFileParams) {
  return request.post(
    {
      url: APIS.uploadFile,
      headers: {
        'Content-Type': 'multipart/form-data', // 指定请求头的Content-Type为multipart/form-data，适用于文件上传
      },
      params: requestData,
      timeout: 1000 * 60,
    },
    { isTransformResponse: false, retry: { count: 0, delay: 1000 } },
  );
}
